﻿function vk_manager_class() {
    var APP_ID = 3377560;
    this.session;
    var _this = this;

    this.init = function () {
        VK.init({
            apiId: APP_ID
        });
    };

    this.login = function () {
        VK.Auth.login(this.on_login);
    };

    this.login_callback = function (data) {
        if (data.status == "connected") {
            _this.session = data.session;

        }
        else {
        }
    };

    this.on_login = function(data) {
        if (data.status == "connected") {
            setCookie('vk_user', JSON.stringify(encodeUserToCookie(data.session.user)));
            vk_login(data);
        } else {
        }
    };

    this.status = function (callback) {
        VK.Auth.getLoginStatus(callback || this.login_callback);
    };


    this.logout = function () {
        VK.Auth.logout(function (data) {
            setCookie("vk_user", null);
            vk_login(data);
        });
    };

    this.init();
    
};

var vk_manager = new vk_manager_class();